import { ADD_COUNT, SUB_COUNT, GET_NEWS } from './actionType'
// 仓库数据
const defaultState = {
  count: 1,
  news: []
}
const reducer = (state = defaultState, action) => {
  // reducer 不允许直接修改 state的数据
  if (action.type === ADD_COUNT) {
    const newState = {
      ...state,
      count: state.count + action.value
    }
    return newState
  }

  if (action.type === SUB_COUNT) {
    const newState = {
      ...state,
      count: state.count - action.value
    }
    return newState
  }

  if (action.type === GET_NEWS) {
    const newState = {
      ...state,
      news: action.value
    }
    return newState
  }
  return state
}

export default reducer